package cn.edu.seu.herald.meq;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MeqServlet extends HttpServlet {
	
	@Override
	public void doGet(HttpServletRequest request,
			HttpServletResponse response)
					throws ServletException, IOException {
		doPost(request, response);
	}
	
	@Override
	public void doPost(HttpServletRequest request,
			HttpServletResponse response)
					throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		PrintWriter out = response.getWriter();
		
		if (username == null || password == null) {
			out.print("用户名和密码错误");
			return;
		}
		
		try {
			MorningExerciseQuery query =
					new MorningExerciseQuery(username, password);
			query.execute();
			out.print("跑操次数：" + query.getResult());
		} catch (QueryFailure f) {
			out.print("不能连接上体育系服务器或验证失败");
			return;
		}
	}

}
